package com.py.credit.service.impl;

import com.py.credit.dao.RuleBindingDao;
import com.py.credit.service.RuleBindingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RuleBindingServiceImpl implements RuleBindingService {

    @Autowired
    RuleBindingDao ruleBindingDao;

    @Override
    public void addTableRuleBinding(int rule_id, int table_id, Integer version) {
        ruleBindingDao.addTableRuleBinding(rule_id, table_id, version);

    }

    @Override
    public void addColmnBinding(int rule_id, String filed_code, String extend, Integer version) {
        ruleBindingDao.addColmnBinding(rule_id, filed_code, version, extend);
    }

    /**
     * @param id
     * @param rule_id  规则ID
     * @param table_id 表ID
     * @param extend   扩展
     * @param isDel    是否删除
     * @Function 插入更新表规则绑定信息，ID不存在插入，ID存在更新
     * @FileName RuleBindingServiceImpl.java
     * @MethodName updateTableBinding
     * @Date 2018年6月12日 上午9:55:10
     * @Author Min DongXv
     */
    @Override
    public void updateTableBinding(Long id, int rule_id, int table_id, String extend, String isDel, Integer version) {
        ruleBindingDao.updateTableBinding(id, rule_id, table_id, version, extend, isDel);
    }

    /**
     * 功能描述: 更新字段绑定规则，id不存在插入，否则更新
     *
     * @param id
     * @param rule_id  规则ID
     * @param filed_code
     * @param extend
     * @param isDel
     * @author Min DongXv
     * @date 18/6/11 17:40
     */
    @Override
    public void updateColmnBinding(Long id, int rule_id, String filed_code, String extend, String isDel,
                                   Integer version) {
        ruleBindingDao.updateColmnBinding(id, rule_id, filed_code, version, extend, isDel);

    }

    @Override
    public void copyTableBingding(int rule_id, int table_id, int old_edition_id, int new_edition_id) {
        ruleBindingDao.copyTableBingding(rule_id, table_id, old_edition_id, new_edition_id);

    }

    @Override
    public void copyColmnBingding(int rule_id, String filed_code, int old_edition_id, int new_edition_id,
                                  String extend) {
        ruleBindingDao.copyColmnBingding(rule_id, filed_code, old_edition_id, new_edition_id, extend);

    }

    @Override
    public List<Integer> selectTableBinding(int table_id, Integer version) {
        return ruleBindingDao.selectTableBinding(table_id, version);
    }

    @Override
    public List<Map<String, Object>> selectColmnBinding(String filed_code, Integer version) {
        return ruleBindingDao.selectColmnBinding(filed_code, version);
    }

    /**
     * @return
     * @Function 获取当前启用版本
     * @FileName RuleBindingServiceImpl.java
     * @MethodName selectCurrentContentVersion
     * @Date 2018年7月26日 下午4:14:17
     * @Author Min DongXv
     */
    @Override
    public Integer selectCurrentContentVersion() {
        return ruleBindingDao.selectCurrentContentVersion();
    }

    @Override
    public void bindTableRule(int ruleId, String extend, String tableId, Integer version) {
        ruleBindingDao.addTableRuleBind(ruleId, extend, tableId, version);

    }

    @Override
    public void bindColumnRule(int ruleId, String extend, int fieldId, String fieldCode, String tableId, Integer version) {
        ruleBindingDao.addColumnRuleBind(ruleId, extend, fieldId, fieldCode, tableId, version);

    }

    @Override
    public void deleteBindColumnRule(int ruleId, Integer tableId, int fieldId, Integer version) {
        ruleBindingDao.deleteBindColumnRule(ruleId, tableId, fieldId, version);

    }

    @Override
    public void deleteBindTableRule(int ruleId, int tableId, Integer version) {
        ruleBindingDao.deleteBindTableRule(ruleId, tableId, version);

    }


}
